package com.bdqn.t308.service.impl;

import com.bdqn.t308.dao.UserDao;
import com.bdqn.t308.dao.impl.UserDaoImpl;
import com.bdqn.t308.entity.User;
import com.bdqn.t308.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl  implements UserService {

    //传统的方式：手动new一个dao实例，如果这个dao实例换了实现类，则需要手动替换该实现类
    //在没有IOC程序中，我们对象与依赖对象之间的关系完全是靠硬编码的形式确定
    //private UserDao userDao = new UserDaoImpl();

    //留出接口，不主动实例化
    //@Autowired
    @Resource
    private UserDao userDao;

    //使用注解实现依赖注入之后，也不再需要set方法与构造方法
    /*public UserServiceImpl() {
    }

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    //利用set方法注入
    public void setUserDao(UserDao userDao){

        this.userDao = userDao;
    }*/


    @Override
    public int save(User user) {

        return userDao.save(user);
    }

}
